const BASE_URL = 'https://tea.qingnian8.com/api/bizhi'

export function request (config={}) {
	// config= { } config有值就有值没值就是个空对象
	let { 
		url,
		data={},
		method="GET",  //结构出来默认是GET请求，如果是POST则会覆盖
		header={
			'access-key':'459972',
		},	
	} = config
	
	return new Promise((resolve,reject)=>{
		uni.request({
		 	url:`${BASE_URL}${url}`,
			data,
			method,
			header,
			success: res => {
				if(res.data.errCode === 0){
					resolve(res.data)
				}else if( res.data.errCode === 400 ){
					uni.showModal({
						title:"错误提示",
						content: res.data.errMsg,
						showCancel:false,
					})
					resolve(res.data)
				} else {
					uni.showToast({
						title:res.data.errMsg,
						icon:"none"
					})
				}
			},
			fail: err => {
				reject(err)
			}
		 })
	})
}